<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <link rel="stylesheet" type="text/css" href="../../css/weui.min.css" />
    <link rel="stylesheet" type="text/css" href="../../css/jquery-weui.min.css" />
    <link rel="stylesheet" type="text/css" href="../../css/index.css" />
    <link rel="stylesheet" type="text/css" href="../../css/order.css" />
    <link rel="stylesheet" type="text/css" href="https://at.alicdn.com/t/font_546019_o8qxm6fupb0ggb9.css" />
    <title>物料列表</title>
    <script src="../../js/jquery-2.1.4.js" type="text/javascript" charset="utf-8"></script>
    <script src="../../js/jquery-weui.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="../../js/baseConfig.js" type="text/javascript" charset="utf-8"></script>
</head>
<style>
    .fault-tolerant {
        width: 100%;
        height: 80%;
        text-align: center;
        display: none
    }
    
    .fault-tolerant img {
        margin-top: 5rem;
    }
    
    .fault-tolerant span {
        width: 100%;
        height: auto;
        text-align: center;
        display: inline-block;
        font-size: 0.8rem;
        padding-top: 1rem
    }
    
    .demos-content-padded {
        position: fixed;
        width: 100%;
        bottom: 0;
        left: 0;
        height: 2.5rem;
        line-height: 2.5rem;
        margin-bottom: 0;
        padding: 0;
        background: #fff;
        border-top: 1px solid #e2e2e2
    }
    
    .demos-content-padded a {
        width: 50%;
        float: left;
        box-sizing: border-box;
        text-align: center;
        display: inline-block;
        color: #444;
    }
    .header-title em a{
    	color: #9c9c9c;
    }
</style>

<body>
    <div id="header">
        <div class="header-title" style="position: fixed;top: 0;">
            <!--<img src="../../img/left.png" class="left" />
				<span>物料列表</span>-->
            <em><a href="javascript:;">下一步</a></em>
        </div>
    </div>
    <div class="addNeworder" style="margin-bottom:2.5rem ">
        <div class="material-list">
            <ul class="material_list">

            </ul>
        </div>
    </div>
    <div class="demos-content-padded">
        <!--<a href="javascript:;" class=" default" style="border-right: 1px solid #e2e2e2">取消</a>-->
        <a href="javascript:;" class=" primary weui-btn_primary" style="width: 100%;color: #fff;">添加物料</a>
    </div>
    <div class="fault-tolerant">
        <img src="../../img/box.png" alt="">
        <span>暂无物料，请点击下方添加物料</span>
    </div>
</body>
<script type="text/javascript">
    $(document).ready(function() {
        baseConfig.historyBack()
            //点击取消就是删除订单
        var orderid = baseConfig.GetQueryString("orderid")
            // var type = baseConfig.GetQueryString("type")
//      $(".default").on("click", function() {
            // $.confirm("取消后您可以在订单列表里进行该订单的其它操作，是否继续", function() {
//          location.href = "../../index.html"
                //					location.href = "http://www.hsw.com/a/weixinMyCenter"
                // }, function() {

            // })
            //				location.href = "http://www.hsw.com/a/weixinMyCenter"
//      })
        $(".header-title em a").on("click", function() {
            if ($(".material_list li").length < 1) {
                $.toptip("请先添加物料", 1200, 'error');
            } else {
                location.href = "waitsubmitOrder.html?orderid=" + orderid
            }
        })
        var orderNo = baseConfig.GetQueryString("orderNo");
        $.ajax({
            type: "get",
            url: baseConfig.localHttp2 + "api/order/getOrderMaterialList",
            async: false,
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded',
            },
            data: {
                orderNo: orderNo
            },
            success: function(data) {
                if (data.code == 100) {
                    var content = data.content;
                    if(content.length<=0){
                    	$(".fault-tolerant").show()
                    }else{
                    	$(".fault-tolerant").hide()
                    }
                    var $li = "";
                    for (var i = 0; i < content.length; i++) {
                        $li += "<li data-id=" + content[i].id + "><p><span>" + content[i].materialName + "</span><img src='../../img/right.png' /></p>"
                        $li += "<p><span>物料重量</span><b>" + content[i].weight + "<em>吨</em></b></p>"
                        $li += "<p><span>物料单价</span><b>" + content[i].unitPrice + "<em>元/吨</em></b></p>"
                        $li += "<p><span>含杂比例</span><b>" + content[i].zazhiPercent + "<em>%</em></b></p></li>"
                    }
                    $(".material_list").append($li)
                    for (var j = 0; j < $(".material_list li").length; j++) {
                        $(".material_list li").eq(j).on("click", function() {
                            var index = $(this).index()
                            location.href = "deleteMaterial.html?orderid=" + orderid + "&orderNo=" + orderNo + "&id=" + $(this).attr("data-id") + "&weight=" + content[index].weight + "&materialName=" + content[index].materialName + "&unitPrice=" + content[index].unitPrice + "&zazhiPercent=" + content[index].zazhiPercent + "&materialNo=" + content[index].materialNo;
                        })
                    }
                } else {
                    $(".fault-tolerant").show()
                }
            },
            error: function() {

            }
        })
        $(".demos-content-padded .primary").on("click", function() {
            location.href = "addMaterial.html?orderNo=" + orderNo + "&orderid=" + orderid
        })
    })
</script>

</html>